/**
  ETFAna project, Anyang Normal University && IMP-CAS
  \class ETFTrackTa
  \brief the track exclusively coined for global tracking (ameliorated tracking)
    consisting of a preTaTrk and a postTaTrk
  \author SUN Yazhou, asia.rabbit@163.com
  \since 2021-11-12
  \date 2021-11-12 last modified
  \attention
  changelog
  <table>
  <tr>  <th>Date         <th>Author      <th>Description                   </tr>
  <tr>  <td>2021-11-12   <td>Asia Sun    <td>file created                  </tr>
  </table>

  \copyright Copyright (c) 2021-2024 Anyang Normal U. && IMP-CAS with LGPLv3 LICENSE
*/

#ifndef ETFTrackTa4_h
#define ETFTrackTa4_h

#include "ETFVTrack.h"

class ETFTrackTa;

class ETFTrackTa4 : public ETFVTrack{
public:
  ETFTrackTa4();
  ETFTrackTa4(const ETFTrackTa4 &t); ///< copy ctor
  ETFTrackTa4 &operator=(const ETFTrackTa4 &t); ///< assignment ctor
  virtual ~ETFTrackTa4();

  virtual void Initialize() override;
  virtual void copy(const ETFVTrack *t) override; ///< the same as copy ctor
  virtual ETFDCHit *operator[](int layerId) const override;

  ETFTrackTa *GetPreTaTrack() const{ return fPreTaTrk; }
  ETFTrackTa *GetPostTaTrack() const{ return fPostTaTrk; }
  virtual int GetNofHits() const override;
  virtual map<int, ETFDCHit *> &GetHits() override;
  virtual const map<int, ETFDCHit *> &GetHits() const override;
  virtual void AddHit(ETFDCHit *h) override;
  virtual void Print(const char *opt = "") const override; ///< print the track info

  virtual void Draw(const char *opt = "") override; ///< draw the track as TGraph
  virtual void SetId(int id, short type) override; ///< number the track
  virtual void SetHitFiredStatus(int s) override; ///< set hit fired status for all hits

  /// fit the track with drift distance info. Note that this is a united fit
  /// additional terms are added to chi2 to ameliorate the fitting
  virtual bool Fit() override; ///< \retval true: if the fitting result meets user criteria
  virtual void UpdateChi() override; ///< update the hits' chis using the current (k, b)
  virtual int EnoughHit() override; ///< specify the criteria that how many hits qualify a good track
  void SetPostMagTrk(double k, double b){ fK3 = k; fB3 = b; }
  virtual void ConstructGraph(double z0, double z1) override; ///< update fGraph in [z0, z1]
  virtual bool GoodFit() const override; ///< test if a fit is a good fit

  virtual void SetHitPos(const string &d, double x) override;
  /// assign hit pos at det's central plane
  virtual void UpdateHitPos(ETFDetector *det) override;
  virtual void UpdateDriftTime() override; ///< update drift times for all member hits
  using ETFVTrack::SetChiPD;
  /// \param c0,1: for pre(post)Ta tracks
  virtual void SetChiPD(double c0, double c1); // user-input chiPD

  double dx2() const{ return fDx2; }
  double dxTa() const{ return fDxTa; }

  ClassDefOverride(ETFTrackTa4, 1);

protected:
  ETFTrackTa *fPreTaTrk; //->
  ETFTrackTa *fPostTaTrk; //->
  double fK3, fB3; ///< l: x=fK3*z+fB3, postMagTrk
  double fDx2; ///< x2-x2p: x2 calculated from postMagTrk - x2 from arc in the mag
  /// the difference of TaHitX between the results of pre- and post-TA track
  double fDxTa; ///< DxTa0(preTa) - DxTa0(postTa)
};

#endif
